package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.config.AlipayTemplate;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.PayVo;;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: charls
 * @Description:TODO
 * @Date: 2023/06/30/ 15:59
 * @Version: 1.0
 */
@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;

    /**
     * 1.将支付页让浏览器显示
     * 2.支付成功以后，我们要跳到用户的订单列表项
     * @param orderSn
     * @return
     * @throws AlipayApiException
     */
    @GetMapping(value = "/payOrder",produces = "text/html")
    @ResponseBody
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        //获取支付订单信息
        PayVo payVo=orderService.getPayOrder(orderSn);
        String pay = alipayTemplate.pay(payVo);
        System.out.println(pay);
        //我们发现返回的是一个页面。将页面直接返回给浏览器就行
        return pay;
    }
}
